build:
	docker build -t mysql-alpine:latest .

setup: build
	mkdir -p /data
	rm -rf /data/mysql
	docker run --rm -it -v/data/mysql:/var/lib/mysql mysql-alpine sh -c " \
	apk add --no-cache mysql-client \
	&& rc default \
	&& /etc/init.d/mariadb setup \
	&& rc-service mariadb start \
	&& mysql -e \"CREATE USER 'root'@'%' IDENTIFIED BY '123456';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';FLUSH PRIVILEGES;\" "

run: setup
	docker stop mysql
	docker rm mysql
	docker run -d --restart=always -p3306:3306 -v/data/mysql:/var/lib/mysql --name mysql mysql-alpine /usr/local/bin/start.sh
		
dump: setup
	docker save mysql-alpine:latest | xz > docker.mysql-alpine.tar.xz
	tar cfJ mysql.data.tar.xz /data/mysql
	
load:
	docker load < docker.mysql-alpine.tar.xz
	tar xf mysql.data.tar.xz -C /

